#pragma once

#include "Protocol.h"
#include "Header.h"

class VoiceChat
{
private:
    static const int RBuffLen = 1024 * 1024;
    static const int WBuffLen = 1024 * 1024;

    //message type
    static const unsigned char Entry_MSG = 0x01;
    static const unsigned char TalkMdiy_MSG = 0x02;
    static const unsigned char Audio_MSG = 0x03;

    //modify talk properties
    static const unsigned char NoTalk_MDIY = 0x01;
    static const unsigned char NoMic_MDIY = 0x02;

public:
    VoiceChat(uint16_t port);
    ~VoiceChat();
    void Run();

private:
    void OnEntry(char *playload, sockaddr *from);
    void Talk_Modify(char *playload, sockaddr *from);
    void Broadcast(char *playload, int playload_size, sockaddr *from);
    uint32_t HashCode(sockaddr *addr);

private:
    int socket_fd;
    sockaddr from;
    socklen_t fromAddrLength;
    std::map<uint32_t, Talker *> talkers;
    char *send_buf;
    char *recv_buf;
};
